<?php
class BrandController extends CommonController{
	public $_model;
	public function __init(){
		$this->_model = K('Brand');
	}
	public function index(){
		$data = $this->_model->get_all_logo(null,true);
		$this->assign('page',$data['page']);
		//在分页分配完成之后，$data['page']就没用了
		//如果继续留着循环就会出问题
		unset($data['page']);
		$this->assign('data',$data);
		
		$this->display();
	}
	
	public function addbr(){
		if(IS_POST){
			if(!$this->_model->add_data()){
				$this->error($this->_model->error);			

			}
			$this->success('添加成功',U('index'));
		}
		$this->display();
	}
	
	
	//修改品牌
	public function editbr(){
//		p($_POST);
		if(IS_POST){
			$this->_model->update_br(array('bid'=>Q('post.bid',0,'intval')));
			$this->success('修改成功',U('Brand/index'));
		}
		//获取旧数据
		$olddata = $this->_model->get_one_logo(array('bid'=>Q('post.bid',0,'intval')));
		$this->assign('olddata',$olddata);
		
		$this->display();
	}
	
	
	//删除
	public function del(){
		if($this->_model->delete_br(Q('get.bid',0,'intval'))){
		$this->success('删除成功');
		}
		$this->error($this->_model->error);
	}
	// upload 方法 接收来自 uploadify的处理请求
	  public function upload()
    {
        $upload = new Upload();
        $file = $upload->upload();
        if (empty($file)) {
            $this->ajax('上传失败');
        } else {
            $data = $file[0];
//			file_put_contents("1.php", var_export($data,true));
			// uploadify 接收的数据
            $this->ajax($data);
        }
    }
	
	
}//end
